package ylesanded.kimpExample;

import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;

public class Line extends Shape {
	
//	Point point = new Point();
	ArrayList<Point> points = new ArrayList<Point>(); 
	
	public Line() {
		
	}
	
	public Line(Point p) {
		points.add(p);
	}
	
	public void paint(Graphics g) {
		super.paint(g);
		ArrayList<Point> newpoints = new ArrayList<Point>(this.points);
	    for (int i = 0; i < newpoints.size() - 2; i++)
	    {
	        Point p1 = newpoints.get(i);
	        Point p2 = newpoints.get(i + 1);
	        g.drawLine(p1.x, p1.y, p2.x, p2.y);
	    }
	}

	@Override
	public Line copy() {
		Line l = new Line();
		copyHelper(l);
		l.points = new ArrayList<>(this.points);
		return l;
	}

	@Override
	public void draw(Point p) {
		// TODO Auto-generated method stub
		this.points.add(p);
		
	}

	@Override
	public void move(int dx, int dy) {
		// TODO Auto-generated method stub
		for (Point point : points) {
			point.x += dx;
			point.y += dy;
		}
		
	}

	@Override
	public int getDistance(Point p) {
		// TODO Auto-generated method stub
		int MinDist = 1000;
		for (Point point : points) {
			int ActDist = (int) p.distance(point);
			if (MinDist > ActDist ) {
				MinDist = ActDist;
			}
		}
		return MinDist;
	}

}
